package 图片处理;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.concurrent.CountDownLatch;

/**
 * @author zhaozeyang
 * @date 2018/11/8 16:26
 * @description
 */
public class PicTask implements Runnable {

    private String picUrl;

    private CountDownLatch countDownLatch;

    private int num;

    public PicTask(String picUrl, CountDownLatch countDownLatch, int num) {
        this.picUrl = picUrl;
        this.countDownLatch = countDownLatch;
        this.num = num;
    }

    @Override
    public void run() {
        try {
            InputStream is = new URL(this.picUrl).openStream();
            BufferedImage sourceImg = ImageIO.read(is);
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            System.out.println(this.num + ":::" + width + ":" + height+"--"+Thread.currentThread().getName());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            countDownLatch.countDown();
        }
    }
}
